<template>
  <scroll-view scroll-y class="side-classify-list-container">
    <view v-for="item in  list " :key="item.id" :class="item.all_ids_.includes(selected) ? 'selected' : ''">
      <view class="label main-label" :class="item.all_ids_ === selected ? 'active' : ''"
        @tap="() => toFilter(item.all_ids_)">{{
          item.name }}</view>
      <view class="inner-list-container">
        <view v-for="it in item.children " :key="it.id" @tap="() => toFilter(it.all_ids_)">
          <view class="label" :class="it.all_ids_ === selected ? 'active' : ''">{{ it.name }}</view>
        </view>
      </view>
    </view>
  </scroll-view>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue"
import type { typeItemData } from '@/types/category';
import Apis from "@/services/modules/category"

const Emits = defineEmits(["toFilter"])

onMounted(() => {
  listTypeDataByCompany()
})

const list = ref<typeItemData[]>()
const listTypeDataByCompany = async () => {
  const { data } = await Apis.listTypeByCompany({
    companyId: 1,
  })
  list.value = data.children
}

const selected = ref()

const toFilter = (e: string) => {
  selected.value = e

  Emits("toFilter", e)
}

</script>

<style lang="scss">
.side-classify-list-container {
  height: 100%;
  width: 100px;
  background: #f6f6f6;
  font-size: 14px;
  overflow: hidden;

  .inner-list-container {
    display: none;
    background: #fff;
  }

  .label {
    padding: 18px 14px;
  }

  .selected {
    position: relative;

    &::after {
      content: "";
      position: absolute;
      width: 5px;
      height: 100%;
      top: 0;
      left: 0;
      background-color: $uni-color-warning;
    }

    .main-label {
      border-bottom: 1px solid #f6f6f6;
    }

    .active {
      color: $uni-color-warning;
    }

    .label {
      background: #fff;
    }

    .inner-list-container {
      display: block;

      .label {
        padding: 12px 14px;
      }
    }
  }
}
</style>
